package schooltest;

import school.Course;
import school.Student;
import school.Teacher;
import java.util.ArrayList;
import java.util.List;

// 测试类：调整package，调用子类重写的父类方法，验证继承与权限
public class TestCourse {
    private List<Teacher> teachers;
    private List<Student> students;
    private List<Course> courses;
    private int courseIdCounter;  // 实验二原有：课程ID计数器

    public TestCourse() {
        teachers = new ArrayList<>();
        students = new ArrayList<>();
        courses = new ArrayList<>();
        courseIdCounter = 1;  // 实验二原有：ID从1开始
    }

    // 实验二原有：创建教师方法（保留，仅调整参数与父类构造匹配）
    public Teacher createTeacher(int teacherId, String name, String gender, String phoneNumber) {
        Teacher teacher = new Teacher(teacherId, name, gender, phoneNumber);
        teachers.add(teacher);
        return teacher;
    }

    // 实验二原有：为教师添加课程方法（保留）
    public Course addCourseToTeacher(Teacher teacher, String courseName, String location, String time, double credits) {
        Course course = new Course(courseIdCounter++, courseName, location, time, credits);
        teacher.addCourse(course);
        courses.add(course);
        return course;
    }

    // 实验二原有：创建学生方法（保留，仅调整参数与父类构造匹配）
    public Student createStudent(int studentId, String name, String gender, int grade, String major) {
        Student student = new Student(studentId, name, gender, grade, major);
        students.add(student);
        return student;
    }

    // 核心调整：调用父类重写方法printWorksheet()，替代原printTimetable()和openCourses()
    public void runSimulation() {
        // 1. 实验二原有：创建3位教师（保留）
        Teacher teacher1 = createTeacher(1, "张老师", "男", "13800138001");
        Teacher teacher2 = createTeacher(2, "李老师", "女", "13900139002");
        Teacher teacher3 = createTeacher(3, "王老师", "男", "13700137003");

        // 2. 实验二原有：为教师添加课程（1、2、3门，保留）
        Course course1 = addCourseToTeacher(teacher1, "Java编程基础", "教学楼A101", "周一8:00-9:40", 3.0);
        Course course2 = addCourseToTeacher(teacher2, "数据结构", "教学楼B201", "周二10:00-11:40", 4.0);
        Course course3 = addCourseToTeacher(teacher2, "算法分析", "教学楼B202", "周四10:00-11:40", 3.5);
        Course course4 = addCourseToTeacher(teacher3, "计算机网络", "教学楼C301", "周三19:00-20:35", 2.0);
        Course course5 = addCourseToTeacher(teacher3, "操作系统", "教学楼C302", "周五15:30-17:10", 2.5);
        Course course6 = addCourseToTeacher(teacher3, "数据库原理", "教学楼C303", "周三13:30-15:10", 3.5);

        // 3. 调整：调用Teacher重写的printWorksheet()，展示授课信息
        System.out.println("===== 教师开课信息（父类方法重写） =====");
        teacher1.printWorksheet();
        teacher2.printWorksheet();
        teacher3.printWorksheet();

        // 4. 实验二原有：创建3位学生（保留）
        Student student1 = createStudent(2001, "小明", "男", 2, "物联网");
        Student student2 = createStudent(3002, "小红", "女", 3, "数据科学与大数据技术");
        Student student3 = createStudent(1003, "小刚", "男", 1, "人工智能");

        // 5. 实验二原有：学生选课（保留）
        System.out.println("\n===== 学生选课过程 =====");
        student1.selectCourse(course1);
        student1.selectCourse(course2);
        student1.selectCourse(course4);
        student2.selectCourse(course2);
        student2.selectCourse(course3);
        student2.selectCourse(course5);
        student2.selectCourse(course6);
        student3.selectCourse(course1);
        student3.selectCourse(course4);

        // 6. 调整：调用Student重写的printWorksheet()，打印课表
        System.out.println("\n===== 学生课表信息（父类方法重写） =====");
        student1.printWorksheet();
        student2.printWorksheet();
        student3.printWorksheet();

        // 7. 实验二原有：学生退课（保留）
        System.out.println("\n===== 学生退课操作 =====");
        student2.dropCourse(course5);

        // 8. 调整：退课后调用printWorksheet()，更新课表
        System.out.println("\n===== 退课后的课表 =====");
        student2.printWorksheet();

        // 9. 新增：验证权限控制（不同包访问protected属性，需通过getter，直接访问报错）
        System.out.println("\n===== 权限验证（不同包访问父类属性） =====");
        System.out.println("学生" + student1.getName() + "的学号：" + student1.getId() + "（通过父类getter访问）");
        System.out.println("教师" + teacher1.getName() + "的工号：" + teacher1.getId() + "（通过父类getter访问）");
    }

    public static void main(String[] args) {
        TestCourse test = new TestCourse();
        test.runSimulation();
    }
}
